package com.jobs.producer0.demo;

import com.jobs.common.factory.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;

/**
 * 死信队列之生产者代码
 *
 **/
public class TTLProducer {

    //普通交换机名称
    public static final String NORMAL_EXCHANGE = "ttl3_normal_exchange";

    public static final String NORMAL_RK = "zhangsan";

    public static void main(String[] args) throws Exception{

        Channel channel = RabbitMqUtils.getChannel();

        //死信消息，设置TTL时间  单位是ms  10000ms是10s
        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().expiration("10000").build();

        new AMQP.BasicProperties().builder();

        for (int i = 0; i < 300; i++) {
            String message = "info" + i;
            channel.basicPublish(NORMAL_EXCHANGE, NORMAL_RK, properties, message.getBytes(StandardCharsets.UTF_8));
        }
    }
}

